package com.hailong.hadoop.rpc.protobuf.client;

import com.hailong.hadoop.rpc.protobuf.MyResourceTrackerPB;
import com.hailong.hadoop.rpc.protobuf.proto.MyResourceTrackerMessage;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.ProtobufRpcEngine;
import org.apache.hadoop.ipc.RPC;

import java.net.InetSocketAddress;

/**
 * Created by 31464 on 2022/1/11.
 */
public class ProtobufRPCClient {

    public static void main(String[] args) throws Exception{
        String hostname="localhost";
        int port=8888;
        Configuration config=new Configuration();
        RPC.setProtocolEngine(config,MyResourceTrackerPB.class, ProtobufRpcEngine.class);


        //获取代理

        MyResourceTrackerPB protocolProxy = RPC.getProxy(MyResourceTrackerPB.class, 1, new InetSocketAddress(hostname, port), config);

        MyResourceTrackerMessage.MyRegisterNodeManagerRequestProto.Builder builder = MyResourceTrackerMessage.MyRegisterNodeManagerRequestProto.newBuilder();

        MyResourceTrackerMessage.MyRegisterNodeManagerRequestProto request = builder.setHostname("bigdata01").setCpu(9).setMemory(20).build();

        MyResourceTrackerMessage.MyRegisterNodeManagerResponseProto responseProto = protocolProxy.registerNodeManager(null, request);

        String flag = responseProto.getFlag();

        System.out.println("注册结果:"+flag);

    }
}
